window.onload = function () {
  var vm = new Vue({
    el: "#indexbox",
    data: {
      loginForm: {
        // username: "17600467656",
        // password: "123456",
        username: "",
        password: "",

      },
      url: "",
      cortel: 1,
      corpsd: 1,
      reg: /^1[34578]\d{9}$/,
    },
    created() {
      this.url = this.getParams("url");
      var random = new Date() * 1 + Math.random();
      sessionStorage.setItem("random", random);
    },
    methods: {
      // 获取参数
      getParams(key) {
        var url = window.location.search;
        var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
        var result = url.substr(1).match(reg);
        return result ? decodeURIComponent(result[2]) : null;
      },
      login() {
        var $this = this;
        if (!this.reg.test(this.loginForm.username)) {
          if (this.loginForm.password) {
            this.corpsd = 1;
          }
          this.cortel = 0;
          return;
        }
        if (!this.loginForm.password) {
          this.cortel = 1;
          this.corpsd = 0
          return;
        }
        login_server.login(this.loginForm, function (res) {
          if (res.data.code == 200) {
            // alert("登陆成功");
            $this.reset()
            var token = res.data.data.token;
            sessionStorage.setItem("token", token);
            sessionStorage.userInfo = JSON.stringify(res.data);
            window.location.href = "./../search/搜索结果列表-写字楼_园区按房源.html";

            // if ($this.url) {
            //   window.location.href = $this.url;
            // } else {
            //   // window.location.href = "http://114.113.68.14:9000/home/html/";
            //   window.location.href = "./../search/搜索结果列表-写字楼_园区按房源.html";

            // }
          } else {
            alert(res.data.message);
            return;
          }
        });
      },
      reset() {
        this.cortel = 1;
        this.corpsd = 1
      }
    }
  });
};